package com.qing;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo1 {
    public static void main(String[] args) {
        String[] arrayOfwords={"Hello","World"};
        Stream<String> stream=Arrays.stream(arrayOfwords);

        List<String> words=Arrays.asList("Hello","World");//--->["H","e","l", "o","W","r","d"]
        List<String[]> streamList1=words.stream().map(word->word.split("")).distinct().collect(Collectors.toList());

        List<Stream<String>> streamList2=words.stream().map(word->word.split("")).map(Arrays::stream).distinct().collect(Collectors.toList());
        List<String> streamList3=words.stream().map(word->word.split("")).flatMap(Arrays::stream).distinct().collect(Collectors.toList());
        System.out.println(streamList3);


        List<Integer> numbers=Arrays.asList(1,2,3,4,5);
        System.out.println(numbers.stream().map(n -> n * n).collect(Collectors.toList()));


        List<Integer> numbers1=Arrays.asList(1,2,3);
        List<Integer> numbers2=Arrays.asList(4,5);

        List<int[]> pairs=numbers1.stream().flatMap(i->
                numbers2.stream().map(j->new int[]{i,j})
        ).collect(Collectors.toList());
        System.out.println(pairs);
    }
}
